Conversation
With input consisting solely of delimiters (e.g. a single ASCII space), the whitespace-delimited argument reader would emit a zero-length token. The child process then received an empty-string argument, producing errors like `ls: cannot access ''`. GNU xargs treats a run of delimiters with no content between them as producing no argument at all (the command runs once with zero extra args, like empty input). The reader's EOF handling returned `None` only when no bytes had been read (`i == 0`). Input that was consumed but was pure whitespace left `result` empty while `i > 0`, so the loop fell through and returned an empty argument. Return `None` whenever `result` is empty at EOF, which covers both the no-bytes and whitespace-only cases.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #819 +/- ##
=======================================
Coverage 91.93% 91.93%
=======================================
Files 35 35
Lines 7251 7251
Branches 378 378
=======================================
Hits 6666 6666
Misses 443 443
Partials 142 142 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Commit 46778db has test result changes: GNU findutils testsuite: bfs testsuite: |
| )); | ||
| } | ||
| if i == 0 { | ||
| // Input that consists only of delimiters (whitespace) |
There was a problem hiding this comment.
i don't think it needs such a long comment
|
|
||
| #[test] | ||
| fn xargs_whitespace_only_input() { | ||
| // Input that consists only of delimiters (whitespace) produces no |
There was a problem hiding this comment.
please make this comment shorter too
|
could you please fix the conflict? thanks |
|
Closing as redundant: commit c4fdf2b (#829 "xargs: don't emit an empty argument for a trailing blank"), now on main, makes the same EOF change this PR proposed ( |
Fixes #771.
Problem
When a filename (or any input) given to
xargsconsists solely of an ASCII space,uu xargspasses an empty-string argument to the child process:GNU
xargsinstead treats the lone space as a delimiter and runs the child with no extra arguments:The same discrepancy occurs for any whitespace-only input (space, tab, newline, runs of them) on both stdin and
-a.Root cause
In
src/xargs/mod.rs, theWhitespaceDelimitedArgumentReader::nextloop returnsOk(None)at EOF only when no bytes have been read at all (i == 0). Input that was consumed but consisted purely of delimiters leftresultempty whilei > 0, so the loop fell through and emitted a zero-lengthArgument. xargs then passed that empty string to the child.Fix
At EOF, return
Ok(None)wheneverresultis empty, not only wheni == 0. This makes whitespace-only input behave exactly like empty input (delimiters separate arguments; a run of delimiters with no content between them yields no argument), matching GNUxargs. Thei == 0case is subsumed since no bytes read impliesresultis empty.Behavior of normal tokenization (leading/trailing/multiple delimiters around real content, quoted/escaped args) is unchanged.
Test
Added
xargs_whitespace_only_inputcovering space, tab, mixed whitespace,--no-run-if-empty, and the-arepro from the issue (asserting the child receives zero xargs-provided arguments). All existing xargs tests still pass.The acceptance criterion is GNU
xargsbehavior: whitespace-only input yields no argument.Developed with AI assistance and reviewed by the contributor.